<template>
	<!-- 
	 该代码分为
	 h1为目录中各个文章的title，
	 h2为各个文章的内容分类title，
	  -->
	<view id="DirectionsUse">
		 <view class="directory">
			<view>创作者指南</view>
			<view @click="directoryShow = true"><u-icon name="list" :label="'('+ directoryContent.id +' / '+ directoryList.length + ')'"></u-icon></view>
		</view>
		<!--<view class="robotAndUpdate">
			<view class="top">
				<view>客服</view>
				<view>2018-07-19</view>
			</view>
			<view class="bottomImg">
				<image src="@/static/sy.jpg" mode="widthFix" />
			</view>
		</view>
		<view class="title">
			<view class="h1">关于橙橙 & 新手入门</view>
			<view class="content">你好，无论你是作者，还是创作者的支持者，
				很高兴你发现了橙橙。</view>
		</view>
		<view class="CC_synopsis">
			<view class="CC_title">橙橙简介</view>
			<view class="CC_synopsis_content contentFont">
				web 端运行于浏览器中。非 web 端（包含小程序和 App），Android 平台运行在 v8 引擎中，iOS 平台运行在 iOS 自带的 jscore 引擎中，都没有运行在浏览器或 webview 里。
			</view>
		</view>
		<view class="feature_introduction">
			<view>
				<view class="feature_introduction_title" v-html="directoryContent.content"></view>
				<view class="huiyuan contentFont">
					<view>按月赞助，购买一个月，可以</view>
					<ul>
						<li>解锁所有内容</li>
						<li>解锁私信</li>
						<li>解锁更多创作者提供的回馈</li>
					</ul>
				</view>
				<view class="imageType">
					<view>
						<image :src="directoryContent.cover" mode="widthFix" />
					</view>
				</view>
			</view>
		</view> -->
		<view class="robotAndUpdate">
			   <view class="AssadPants">
				   <view class="title">
				   	{{directoryContent.name}}
				   </view>
			   	    <view class="imageType">
			   	    	<image :src="directoryContent.cover" mode="widthFix" />
			   	    </view>
			   </view>
			 <view class="backdrop">
				<u-parse :content="directoryContent.content"></u-parse>
			 </view>
		</view>
		<view class="functionType">
			<view @click.stop="toggleLove(directoryContent)">
				<u-icon v-if="directoryContent.is_like==2" name="heart" color="red"
					:label="directoryContent.num_like"></u-icon>
				<u-icon v-else name="heart-fill" color="red" :label="directoryContent.num_like"></u-icon>
			</view>
			<view class="star" @click.stop="toggleCollect(directoryContent)">
				<u-icon v-if="directoryContent.is_collection==2" name="star"></u-icon>
				<u-icon v-else name="star-fill" color="#f3f301"></u-icon>
			</view>
			<view>
				<u-icon name="share-square" color="#9271d4" label="分享"></u-icon>
			</view>
		</view>
		<!-- 翻页 -->
		<!-- <view class="pagination">
			<view class="left" @click="togglePageById(item.id)">
				<view class="top">往前翻</view>
				<view>《大武》第一回</view>
			</view>
			<view class="right" @click="togglePageById(item.id)">
				<view class="top">往后翻</view>
				<view>《大武》第三回</view>
			</view>
		</view> -->

		<!-- 评论区 -->
		<view class="opusDetail_comments">
			<view class="title">
				<view>评论{{remarksList.length}}</view>
				<view class="title_button" @click="gotoRemaks(directoryContent.id)">发布评论</view>
			</view>
			<view class="comment_text" v-for="(item,index) in remarksList" :key="index">
				<view>
					<!-- <view class="section_head">
						<view class="headImg">
							<u-avatar :src="item.uuid.headimg"></u-avatar>
						</view>
						<view class="name">
							<view class="nameText">{{item.uuid.nickname}}</view>
							<view class="section_head_name">{{formatTime(item.create_at)}}</view>
						</view>
					</view> -->
					<view class="content_text">
						<view class="headImg"><image src="@/static/niMing.png" mode="widthFix"/></view>
						<view class="name fonSize">{{item.content}}</view>
					</view>
					<!-- 二级评论按钮
					<view class="content_text">
						<view class="headImg"></view>
						
						<view class="name ThumbsUup">
							<view>
								<u-icon name="heart" v-if="!false" label="2" label-size="10"></u-icon>
								<u-icon name="heart-fill" color="red" v-else label="1" label-size="10"></u-icon>
							</view>
							<view style="display: flex;">
								<view class="custom-icon custom-icon-huifu" @click="gotoRemaks(list.id,item.id)">
									<text style="font-size: 24rpx;">回复</text>
								</view>
							</view>
						</view> 
					</view>-->
				</view>
				<!--二级评论
				 <view class="content_text" v-for="(childItem,childIndex) in item.children">
					<view class="headImg"></view>
					<view class="name">
						<view class="section_head">
							<view class="headImg">
								<u-avatar size="30" :src="childItem.uuid.headimg"></u-avatar>
							</view>
							<view class="section_head_name">
								<view class="nameText">{{childItem.uuid.nickname}}</view>
								<view class="name_date">{{formatTime(childItem.create_at)}}</view>
							</view>
						</view>
						<view class="content_text">
							<view class="headImg"></view>
							<view class="name fonSize">{{childItem.content}}</view>
						</view>
						<view class="content_text">


							<view class="headImg"></view>
							<view class="name ThumbsUup">
								<view>
									<u-icon name="heart" v-if="!false" label="1" label-size="10"></u-icon>
									<u-icon name="heart-fill" color="red" v-else label="1" label-size="10"></u-icon>
								</view>
							</view>
						</view>
					</view>
				</view> -->
			</view>
		</view>
		<view>
			
		</view>
		<!-- 目录弹出层 -->
		<u-popup :show="directoryShow" :round="10" mode="bottom" @close="close" @open="open">
			<view class="popup_directory">目录 共{{directoryList.length}}页</view>
			<view v-for="(item,index) in directoryList" :key="index" @click="togglePageById(item.id)">
				<view class="popup_type">
					<view class="popup_title">
						<view class="ordinal">{{index+1}}</view>
						<view class="title">{{item.name}}</view>
					</view>
					<view class="popup_titleDate">{{item.create_at}}</view>
				</view>
			</view>
		</u-popup>
		<u-toast ref="uToast" />


	</view>
</template>

<script>
	export default {
		data() {
			return {
				directoryShow: false, //目录弹出层
				directoryList: [], //目录列表
				directoryContent: {},//单个目录内容
				remarksList:[],
			}
		},
		onLoad(option) {
			var home_id=null
			if(option.id){
				home_id=option.id
			}else{
				home_id=1;
			}
			this.$api.getItem().then(res => {
				console.log("res=>", res)
				this.directoryList = res.data
			})
			this.togglePageById(home_id);
			this.getComment(this.directoryList.id);
		},
		methods: {
			getComment(id){
				this.$api.getComment({
					id:id,
					page:1,
					limit:10
				}).then(res=>{
					console.log("评论",res)
					this.remarksList=res.data.data
				})
			},
			open() {
				// console.log('open');
			},
			close() {
				this.directoryShow = false
				// console.log('close');
			},
			togglePageById(id) {
				this.$api.getHomeDetail({
					id: id
				}).then(res => {
					console.log("res=>", res)
					this.directoryContent = res.data;
					if (res.code == 1) {
						this.directoryShow = false
						this.getComment(this.directoryContent.id)
					}
				})
			},
			// 切换点赞状态
			toggleLove(directoryContent) {
				directoryContent.is_like = directoryContent.is_like === 2 ? 1 : 2;
				// 更新喜欢数量
				directoryContent.num_like += directoryContent.is_like === 2 ? -1 : 1;
				this.$api.addLike({
					home_id: directoryContent.id
				}).then(res => {
					if (res.code == 1) {
						if (directoryContent.is_like == 1) {
							this.$refs.uToast.show({
								message: '点赞成功',
								type: 'success',
								duration: 1000,
								url: ''
							})
						} else {
							this.$refs.uToast.show({
								message: '取消点赞',
								type: 'success',
								duration: 1000,
								url: ''
							})
						}
					}
				})
			},
			// 切换收藏
			toggleCollect(directoryContent) {
				directoryContent.is_collection = directoryContent.is_collection === 2 ? 1 : 2;
				// 更新喜欢数量
				directoryContent.num_collection += directoryContent.is_collection === 2 ? -1 : 1;
				
				
				
				this.$api.addCollection({
					home_id: directoryContent.id
				}).then(res => {
					if (res.code == 1) {
						if (directoryContent.is_collection == 1) {
							this.$refs.uToast.show({
								message: '收藏成功',
								type: 'success',
								duration: 1000,
								url: ''
							})
						} else {
							this.$refs.uToast.show({
								message: '取消收藏',
								type: 'success',
								duration: 1000,
								url: ''
							})
						}
					}
				})
				/* item.collect = !item.collect;
				this.$emit('update:initialValue', this.list) */
			},
			gotoRemaks(id){
				uni.navigateTo({
					url:"/pages/home/remarks/remarks?home_id="+id
				})
				
				
				
			}
		}
	}
</script>

<style scoped lang="scss">
	#DirectionsUse {
		width: 100%;
	}

	.contentFont {
		line-height: 1.5;
		font-size: 24rpx;
	}

	.popup_directory {
		line-height: 4;
		text-indent: 1em;
	}

	.popup_type {
		width: 100%;

		.popup_title {
			display: flex;
			align-items: center;
			height: 80rpx;

			.ordinal {
				width: 100rpx;
				font-size: 30rpx;
				color: #bcbcbc;
				text-align: center;
			}

			.title {
				font-size: 37rpx;
				font-weight: normal;
			}
		}

		.popup_titleDate {
			font-size: 24rpx;
			text-indent: 3em;
			color: #bcbcbc;
			padding: 20rpx;
			// position: relative;
			// top: -20rpx;

		}
	}


	.directory {
		width: 100%;
		line-height: 3;
		display: flex;
		align-items: center;
		justify-content: space-between;
		border-bottom: 1px #e6e6e6 solid;
		position: fixed;
		background: #fff;
		z-index: 999;

		>view {
			width: 30%;
			font-size: 24rpx;
			// border: 1px red solid;
			text-align: center;
			color: #bcbcbc;
		}
	}

	.robotAndUpdate {
		width: 90%;
		margin: auto;
		padding-top: 80rpx;

		.top {
			display: flex;
			justify-content: space-between;
			align-items: center;

			view {
				line-height: 3;
				font-size: 24rpx;
			}
		}

		.bottomImg {
			width: 100%;
			margin: auto;

			image {
				width: 100%;
			}
		}
	}

	.title {
		width: 90%;
		margin: auto;
		font-weight: bold;

		.h1 {
			font-size: 60rpx;
			line-height: 3;
		}

		.content {
			font-size: 35rpx;
			line-height: 1.5;
		}
	}

	.CC_synopsis {
		width: 90%;
		margin: auto;

		.CC_title {
			line-height: 4;
			font-size: 50rpx;
			font-weight: bold;
		}
	}

	.feature_introduction {
		width: 90%;
		margin: auto;

		.feature_introduction_title {
			font-weight: bold;
			font-size: 40rpx;
			line-height: 4;
		}

		.huiyuan {
			ul {
				margin-top: 40rpx;
			}
		}

		.imageType {
			width: 100%;

			view {
				width: 100%;
				// border: 1px red solid;
				padding: 20rpx 0;

				image {
					width: 100%;
				}
			}

		}
	}

	.functionType {
		height: 200rpx;
		display: flex;
		justify-content: space-around;
		align-items: center;

		.star {
			width: 200rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			border-left: 1px solid #f2f2f2;
			border-right: 1px solid #f2f2f2;
		}
	}
	// 分页
	/* .pagination {
		width: 90%;
		margin: auto;
		display: flex;
		justify-content: space-between;

		>view {
			width: 38%;
			padding: 40rpx 30rpx;
			font-size: 30rpx;
			color: #c9c9c9;
			border: 1px #f1f1f1 solid;
		}

		.top {
			font-weight: bold;
			color: #f4ba54;
		}
	} */

	.opusDetail_comments {
		width: 90%;
		margin: auto;
	
		.title {
			display: flex;
			justify-content: space-between;
			align-items: center;
			line-height: 4;
	
			.title_button {
				height: 70rpx;
				line-height: 70rpx;
				font-size: 24rpx;
				font-weight: normal;
			}
		}
	
		.comment_text {
			width: 100%;
	
			.section_head,
			.content_text {
				display: flex;
				align-items: center;
				margin: 20rpx 0;
				.headImg {
					width: 15%;
					border-radius: 1000rpx;
	
					image {
						width: 90%;
						border-radius: 1000rpx;
					}
				}
	
				.name {
					width: 85%;
					// border:1px red solid;
					font-size: 24rpx;
					color: #d3d4d3;
					display: flex;
					justify-content: space-between;
					flex-direction: column;
	
					.section_head {
						width: 100%;
					}
				}
	
				.fonSize {
					color: #000;
					line-height: 2;
					white-space: normal;
					/* 允许文本换行 */
					word-wrap: break-word;
					/* 允许长单词换行 */
					overflow-wrap: break-word;
					/* 确保长单词在需要时换行 */
				}
	
				.ThumbsUup {
					display: flex;
					flex-direction: row;
					align-items: center;
					justify-content: flex-start;
					line-height: 2;
	
					view {
						width: 100rpx;
						// font-size: 24rpx;
					}
				}
			}
	
	
		}
	}
	
	
	//标题
	.robotAndUpdate{
		.AssadPants{
			margin: 20rpx auto;
			border-radius: 10rpx;
			background-color: #ff6600;
			display: flex;
			align-items: center;			
			padding:80rpx 30rpx;
		.title{
			font-size: 37rpx;
			font-weight: normal;
			color: #fff;
		}
		.imageType{
			image{
				width: 100rpx;
				height: 100rpx;
				display: block;
			}
		   }
		}
		.backdrop{
			 margin: 20rpx auto;
		}
	}
	
	
	
	
	
	
	
	
</style>